package com.fastjrun.share.demo.web.controller;

import com.fastjrun.apiworld.helper.ResultHelper;
import com.fastjrun.apiworld.vo.ResultModel;
import com.fastjrun.security.authentication.mobile.MobileConstants;
import com.fastjrun.web.controller.BaseController;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * 注意：本内容仅限于公司内部传阅，禁止外泄以及用于其他的商业目的
 *
 * @author cuiyingfeng
 * @Copyright 2021 快嘉. All rights reserved.
 */
@RestController
@RequestMapping("/mobile")
public class MobileController
        extends BaseController {

    /**
     * 发送验证码
     */
    @RequestMapping(value = "/smsCode", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public ResultModel smsCode(HttpServletRequest request, @RequestParam(name = "phone", required = true) String phone) {
        ResultModel result = ResultHelper.ok();
        // 1. 生成一个手机验证码
        String code = RandomStringUtils.randomNumeric(4);
        log.debug("code={}", code);
        // 2. 将手机验证码保存到session中
        request.getSession().setAttribute(MobileConstants.SESSION_KEY_MOBILE_CODE, code);
        return result;
    }
}
